<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Object-oriented JavaScript example</title>
  </head>

  <body>
    <p>This example requires you to enter commands in your browser's JavaScript console (see <a href="https://developer.mozilla.org/en-US/docs/Learn/Common_questions/What_are_browser_developer_tools">What are browser developer tools</a> for more information).</p>

  </body>

    <script>
        function createNewPerson(name) {
            var obj = {};
            obj.name = name;
            obj.greeting = function () {
                alert('Hi! I\'m ' + this.name + '.');
            }
            return obj;
        }

        var salva = createNewPerson('salva');
        console.log(salva.name);
        salva.greeting();

        function Person(name) {
            this.name = name;
            this.greeting = function() {
                alert('Hi! I\'m ' + this.name + '.');
            };
        }
        var person1 = new Person('bob');
        var person2 = new Person('sarah');
        console.log(person1.name,person2.name)   
    </script>
</html>